Package net.mitza.rel.util

Source Code of net.mitza.rel.util.Utils

package net.mitza.rel.util;

import java.text.ParseException;

import com.tridion.util.TCMURI;

public class Utils {

  public static int getItemId(Object value) {
    if (value == null) {
      return -1;
    }

    if (value instanceof Integer) {
      return (Integer) value;
    } else if (value instanceof TCMURI) {
      return ((TCMURI) value).getItemId();
    } else if (value instanceof String) {
      return getItemId((String) value);
    }

    return -1;
  }

  public static int getItemId(String value) {
    if (value == null) {
      return -1;
    }

    try {
      TCMURI tcmUri = new TCMURI(value);
      return tcmUri.getItemId();
    } catch (ParseException e) {
      try {
        return Integer.parseInt(value);
      } catch (NumberFormatException nfe) {
        return -1;
      }
    }
  }

  public static boolean isValidTcmUri(String value) {
    try {
      new TCMURI(value);
      return true;
    } catch (Exception e) {
      return false;
    }
  }
}
TOP

Related Classes of net.mitza.rel.util.Utils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.